﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Sonce.Common
{
	public static class FrameworkElementExtensions
	{
		public static void SetPosition(this FrameworkElement element, Point position, PositionMode mode /* = PositionMode.Canvas | PositionMode.Center */)
		{
			if ((mode & PositionMode.Center) > 0)
			{
				position.X -= element.Width;
				position.Y -= element.Height;
			}

			if ((mode & PositionMode.Canvas) > 0)
			{
				element.SetValue(Canvas.LeftProperty, position.X);
				element.SetValue(Canvas.TopProperty, position.Y);
			}
			else if ((mode & PositionMode.Canvas) > 0)
			{
				element.Margin = new Thickness(position.X, position.Y, 0, 0);
			}
		}
	}

	[Flags]
	public enum PositionMode
	{
		Canvas = 1,
		Margin = 2,
		Center = 4,
	}
}
